import instance from './instance.js';

// 登录
export const login = (option) => {
  return instance({
    method: 'post',
    url: `/login`,
    data: option,
  });
};

// 搜索
export const search = (text) => {
  return instance({
    url: `/search?text=${text}`,
  });
};
// 获取所有书籍类型
export const getType = () => {
  return instance({
    url: '/getAllType',
  });
};
// 添加操作
export const confirmAdd = (option) => {
  return instance({
    method: 'post',
    url: '/addBook',
    data: option,
  });
};

// 编辑页面
export const edit = (id) => {
  return instance({
    url: `/getOneBook?id=${id}`,
  });
};
// 编辑操作
export const confirmEdit = (id, option) => {
  return instance({
    method: 'put',
    url: `/editOneBook/${id}`,
    data: option,
  });
};
// 删除操作
export const del = (id) => {
  return instance({
    method: 'delete',
    url: `/delBook/${id}`,
  });
};
// 对图书管理进行分页
export const paging = (page, pageSize) => {
  return instance({
    url: `/getPage?page=${page}&pageSize=${pageSize}`,
  });
};

// 添加分类
export const addType = (name) => {
  return instance({
    method: 'post',
    url: '/addType',
    data: { name },
  });
};
// 删除分类
export const delType = (id) => {
  return instance({
    method: 'delete',
    url: `/delType/${id}`,
  });
};
// 编辑分类
export const editType = (id, value) => {
  return instance({
    method: 'put',
    url: `/editType/${id}/${value}`,
  });
};
// 对类型管理进行分页
export const typeLoad = (page, pageSize) => {
  return instance({
    url: `/getType?page=${page}&pageSize=${pageSize}`,
  });
};
// 删除图片
export const cancel = () => {
  return instance({
    method: 'delete',
    url: `/delpicture`,
  });
};

// 获取密码
export const getPwd = () => {
  return instance({
    url: `/getPwd`,
  });
};
// 修改密码
export const changePwd = (option) => {
  return instance({
    method: 'put',
    url: `/changePwd`,
    data: option,
  });
};
// 查找同类型的所有书籍
export const getTypeBooks = (id) => {
  return instance({
    url: `/getTypeBooks?cateId=${id}`,
  });
};
// 搜索类型
export const searchType = (content) => {
  return instance({
    url: `/searchType?content=${content}`,
  });
};
